//
//  JFBoardSettingViewController.m
//  JobFree2.0
//
//  Created by xxcao on 2017/5/27.
//  Copyright © 2017年 Dale. All rights reserved.
//

#import "JFBoardSettingViewController.h"
#import "JFScrumModel.h"
#import "JFCreateBoardCell.h"

@interface JFBoardSettingViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong) NSArray *dataSource;

@end

@implementation JFBoardSettingViewController

- (NSArray *)dataSource {
    if (_dataSource == nil) {
        _dataSource = @[
                        @[@{@"type":@0,
                            @"name":self.model.board_name,
                            @"description":self.model.create_date}],
                        @[@{@"type":@1,
                            @"name":@"名称",
                            @"description":@"请输入名称",
                            @"text":self.model.board_name},
                          @{@"type":@1,
                            @"name":@"备注",
                            @"description":@"请输入备注",
                            @"text":self.model.board_remark}],
                        @[@{@"type":@2,
                            @"name":@"成员",
                            @"description":@"1人",
                            @"members":@[[JFUser mainJFUser],  [[JFUser alloc] init]].mutableCopy}]
                        ];
    }
    return _dataSource;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor purpleColor];
    self.title = @"设置";
    NSLog(@"%@", self.model);
    [self configureLeftNavigationBarItemWithImage:@"backToTeamIcon"];
}

- (void)handleLeftBtnAction {
    [self.tabBarController.navigationController popViewControllerAnimated:YES];
}


//MARK: UITableViewDataSource && Delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataSource.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSArray *secArr = self.dataSource[section];
    return secArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *dic = self.dataSource[indexPath.section][indexPath.row];
    JFCreateBoardCell *cell = [JFCreateBoardCell cellWithTableView:tableView withDic:dic];
    cell.setDic = dic;
    cell.textFieldBlock = ^(NSString *text, int type) {
        if (type == 0) {
            
        } else {

        }
    };
    
    cell.dataSource = dic[@"members"];
    cell.clickMemberBlock = ^(JFCreateBoardCellType type) {
        
    };
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *dic = self.dataSource[indexPath.section][indexPath.row];
    return [JFCreateBoardCell loadCellHeightWithDic:dic];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (section == 0 || section == 1) {
        return 20;
    }
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    if (section == 0 || section == 1) {
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = kRGB(230, 230, 237);
        return view;
    }
    return nil;
}

@end
